//
//  ZH_GoodsCenterTableViewCell.m
//  ChangeMerchants
//
//  Created by zhangliwen on 2018/9/28.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_GoodsCenterTableViewCell.h"
@interface ZH_GoodsCenterTableViewCell()
@property (nonatomic,weak)UILabel *titleLabel;
@property (nonatomic,weak)UIButton *rightButton;
@property (nonatomic,weak)UIImageView *photoImage;
@property (nonatomic,weak)UILabel *nameLabel;
@property (nonatomic,weak)UILabel *timeLabel;
@property (nonatomic,weak)UILabel *contentLabel;
@end
@implementation ZH_GoodsCenterTableViewCell

///创建
+ (instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_GoodsCenterTableViewCell";
    ZH_GoodsCenterTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_GoodsCenterTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
///初始化
-(void)initDefault
{
    [self unShowClickEffect];
    
}
- (void)loadSubviewConstraints{
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(13));
        make.left.equalTo(self.contentView).offset(FITSCALE(22));
    }];
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(12));
        make.right.equalTo(self.contentView).offset(FITSCALE(-22));
    }];
    [self.photoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(FITSCALE(14));
        make.width.mas_equalTo(FITSCALE(30));
        make.height.mas_equalTo(FITSCALE(30));
        make.left.equalTo(self.titleLabel);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.photoImage);
        make.left.equalTo(self.photoImage.mas_right).offset(FITSCALE(6));
         make.right.equalTo(self.contentView).offset(FITSCALE(-22));
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(FITSCALE(8));
        make.left.equalTo(self.nameLabel);
        make.right.equalTo(self.nameLabel);
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.photoImage.mas_bottom).offset(FITSCALE(12));
        make.left.equalTo(self.contentView).offset(FITSCALE(22));
        make.right.equalTo(self.contentView).offset(FITSCALE(-22));
        make.bottom.equalTo(self.contentView).offset(FITSCALE(-9));
    }];
}
- (void)updataUI:(NSDictionary *)dic{
    if (dic) {
        self.titleLabel.text = [NSString stringWithFormat:@"用户评论(%@)",dic[@"goods"][@"replay_count"]];
        [self.photoImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,dic[@"replay"][@"head"]]]];
        self.nameLabel.text = [NSString stringWithFormat:@"%@",dic[@"replay"][@"nickname"]];
        self.timeLabel.text = [NSString stringWithFormat:@"%@",dic[@"replay"][@"create_time"]];
        self.contentLabel.text = [NSString stringWithFormat:@"%@",dic[@"replay"][@"replay_content"]];
    }
}
#pragma mark - getter,setter
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [UILabel createLabelWithText:@"用户评论(15)" font:kFontSize_28];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
- (UIButton *)rightButton{
    if (!_rightButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"全部评论" target:self action:nil];
        [button setTitleColor:[UIColor colorWithHexString:@"#F0302F"] forState:UIControlStateNormal];
        [self.contentView addSubview:_rightButton = button];
    }
    return _rightButton;
}
- (UIImageView *)photoImage{
    if (!_photoImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@""];
        image.backgroundColor = [UIColor redColor];
        image.layer.cornerRadius = FITSCALE(15);
        image.layer.masksToBounds = YES;
        image.clipsToBounds = YES;
        [self.contentView addSubview:_photoImage = image];
    }
    return _photoImage;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        UILabel *label = [UILabel createLabelWithText:@"TT" font:kFontSize_24];
        [self.contentView addSubview:_nameLabel = label];
    }
    return _nameLabel;
}
- (UILabel *)timeLabel{
    if (!_timeLabel) {
        UILabel *label = [UILabel createLabelWithText:@"时间: 2018-08-29" font:kFontSize_22];
        label.textColor = [UIColor colorWithHexString:@"#999999"];
        [self.contentView addSubview:_timeLabel = label];
    }
    return _timeLabel;
}
- (UILabel *)contentLabel{
    if (!_contentLabel) {
        UILabel *label = [UILabel createLabelWithText:@"评论内容, 评论内容,评论内容,评论内容..." font:kFontSize_26];
        [label lableAutoLinefeed];
        [self.contentView addSubview:_contentLabel = label];
    }
    return _contentLabel;
}
@end
